package cn.humaohua.study.hadoop.cmdrunner.c3;

import cn.humaohua.study.hadoop.cmdrunner.Test;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.stereotype.Component;

import java.net.URI;


@Component
public class Mkdirs implements Test {

    @Override
    public void test() throws Exception {
//        String uri = "hdfs://localhost:8020/user/hmh/no/use/dir";//ok
        String uri = "hdfs://localhost/user/hmh/no/use/dir2";//ok
        Configuration conf = new Configuration();
        /**
         * public static FileSystem get(Configuration conf) throws IOException {
         *         return get(getDefaultUri(conf), conf);
         *     }
         *
         *     public static URI getDefaultUri(Configuration conf) {
         *         return URI.create(fixName(conf.get("fs.defaultFS", "file:///")));
         *     }
         */
        FileSystem hdfs = FileSystem.get(URI.create(uri), conf);
        hdfs.mkdirs(new Path(uri));
    }
}
